package cn.mw.cmdb.service;

import cn.mw.cmdb.entity.*;
import cn.mw.cmdb.enums.DefaultMonitorTabEnum;
import cn.mw.cmdb.param.zabbixResult.MwZabbixItemResultParam;
import cn.mw.microMonitorCommon.constants.ZabbixApiConstants;
import cn.mw.microMonitorCommon.entity.zabbix.MWZabbixAPIResult;

import java.util.*;

import static cn.mw.cmdb.enums.BusynessSystemUtilizationEnum.*;
import static cn.mw.cmdb.enums.ChartTypeEnum.*;
import static cn.mw.cmdb.util.ValConvertUtil.intValueConvert;

public class MwAssetsTypeMonitorLayout {
    /**
     * 网络设备，安全设备等默认概览布局
     * @return
     */
    public List<MwTabLayoutInfo> getNetWorkDeviceTypeLayout(Map<String,MwZabbixItemResultParam> map) {
        List<MwTabLayoutInfo> componentLayoutList = new ArrayList<>();
        MwTabLayoutInfo overViewLayout = new MwTabLayoutInfo();
        overViewLayout.setDefaultFlag(true);
        overViewLayout.setResolved(false);
        overViewLayout.setLabelId(DefaultMonitorTabEnum.overView.getId());
        List<MwLayoutDetailInfo> layout = new ArrayList<>();
        MwLayoutDetailInfo layoutDetailInfoCPU = new MwLayoutDetailInfo();
        LayoutGrid layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(0);
        layoutGrid.setW(12);
        layoutGrid.setH(2);
        layoutDetailInfoCPU.setLayoutGrid(layoutGrid);
        layoutDetailInfoCPU.setComponentName("CPU");
        layoutDetailInfoCPU.setComponentType(rateLine.getItemName());
        layoutDetailInfoCPU.setId(UUID.randomUUID().toString());
        MwLayoutItemDropInfo layoutItemDropInfo = new MwLayoutItemDropInfo();
        ItemDropInfo itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(CPU.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("120s");
        itemDropInfo.setValuemapid("0");
        itemDropInfo.setValue_type(0);
        if(map!=null && map.containsKey(CPU.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(CPU.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(CPU.getEnglishName());

        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoCPU.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoCPU);

        MwLayoutDetailInfo layoutDetailInfoMemory = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(2);
        layoutGrid.setW(12);
        layoutGrid.setH(2);
        layoutDetailInfoMemory.setLayoutGrid(layoutGrid);
        layoutDetailInfoMemory.setComponentName("内存");
        layoutDetailInfoMemory.setComponentType(rateLine.getItemName());
        layoutDetailInfoMemory.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(MEMORY.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("120s");
        itemDropInfo.setValue_type(0);
        itemDropInfo.setValuemapid("0");
        if(map!=null && map.containsKey(MEMORY.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(MEMORY.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(MEMORY.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoMemory.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoMemory);

        MwLayoutDetailInfo layoutDetailInfoInterface = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(4);
        layoutGrid.setW(12);
        layoutGrid.setH(2);
        layoutDetailInfoInterface.setLayoutGrid(layoutGrid);
        layoutDetailInfoInterface.setComponentName("接口");
        layoutDetailInfoInterface.setComponentType(line.getItemName());
        layoutDetailInfoInterface.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        ItemDropInfo itemDropInfoInterface01 = new ItemDropInfo();
        itemDropInfoInterface01.setChName(INTERFACE_IN.getChineseName());
        itemDropInfoInterface01.setUnits("bps");
        itemDropInfoInterface01.setDelay("120s");
        itemDropInfoInterface01.setValue_type(3);
        itemDropInfoInterface01.setValuemapid("0");
        if(map!=null && map.containsKey(INTERFACE_IN.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(INTERFACE_IN.getEnglishName());
            itemDropInfoInterface01.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfoInterface01.setUnits(resultParam.getUnits());
            itemDropInfoInterface01.setDelay(resultParam.getDelay());
            itemDropInfoInterface01.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfoInterface01.setName(INTERFACE_IN.getEnglishName());

        ItemDropInfo itemDropInfoInterface02 = new ItemDropInfo();
        itemDropInfoInterface02.setChName(INTERFACE_OUT.getChineseName());
        itemDropInfoInterface02.setUnits("bps");
        itemDropInfoInterface02.setDelay("120s");
        itemDropInfoInterface02.setValue_type(3);
        itemDropInfoInterface02.setValuemapid("0");
        if(map!=null && map.containsKey(INTERFACE_OUT.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(INTERFACE_OUT.getEnglishName());
            itemDropInfoInterface02.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfoInterface02.setUnits(resultParam.getUnits());
            itemDropInfoInterface02.setDelay(resultParam.getDelay());
            itemDropInfoInterface02.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfoInterface02.setName(INTERFACE_OUT.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfoInterface01, itemDropInfoInterface02));
        layoutDetailInfoInterface.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoInterface);
        overViewLayout.setLayout(layout);
        componentLayoutList.add(overViewLayout);
        return componentLayoutList;
    }

    /**
     * 服务器概览布局
     * @return
     */
    public List<MwTabLayoutInfo>  getServerDeviceTypeLayout(Map<String, MwZabbixItemResultParam> map) {
        List<MwTabLayoutInfo> componentLayoutList = new ArrayList<>();
        MwTabLayoutInfo overViewLayout = new MwTabLayoutInfo();
        overViewLayout.setDefaultFlag(true);
        overViewLayout.setResolved(false);
        overViewLayout.setLabelId(DefaultMonitorTabEnum.overView.getId());
        List<MwLayoutDetailInfo> layout = new ArrayList<>();
        //CPU利用率
        MwLayoutDetailInfo layoutDetailInfoCPU = new MwLayoutDetailInfo();
        LayoutGrid layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(0);
        layoutGrid.setW(6);
        layoutGrid.setH(2);
        layoutDetailInfoCPU.setLayoutGrid(layoutGrid);
        layoutDetailInfoCPU.setComponentName("CPU");
        layoutDetailInfoCPU.setComponentType(rateLine.getItemName());
        layoutDetailInfoCPU.setId(UUID.randomUUID().toString());
        MwLayoutItemDropInfo layoutItemDropInfo = new MwLayoutItemDropInfo();
        ItemDropInfo itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(CPU.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("120s");
        itemDropInfo.setValuemapid("0");
        itemDropInfo.setValue_type(0);
        if(map!=null && map.containsKey(CPU.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(CPU.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(CPU.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoCPU.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoCPU);
        //磁盘饼状图
        MwLayoutDetailInfo layoutDetailInfoDISK = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(6);
        layoutGrid.setY(0);
        layoutGrid.setW(6);
        layoutGrid.setH(2);
        layoutDetailInfoDISK.setLayoutGrid(layoutGrid);
        layoutDetailInfoDISK.setComponentName("磁盘");
        layoutDetailInfoDISK.setComponentType(pie.getItemName());
        layoutDetailInfoDISK.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(DISK.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("600s");
        itemDropInfo.setValue_type(0);
        itemDropInfo.setValuemapid("0");
        if(map!=null && map.containsKey(DISK.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(DISK.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(DISK.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoDISK.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoDISK);

        //内存利用率
        MwLayoutDetailInfo layoutDetailInfoMemory = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(2);
        layoutGrid.setW(6);
        layoutGrid.setH(2);
        layoutDetailInfoMemory.setLayoutGrid(layoutGrid);
        layoutDetailInfoMemory.setComponentName("内存");
        layoutDetailInfoMemory.setComponentType(rateLine.getItemName());
        layoutDetailInfoMemory.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(MEMORY.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("120s");
        itemDropInfo.setValue_type(0);
        itemDropInfo.setValuemapid("0");
        if(map!=null && map.containsKey(MEMORY.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(MEMORY.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(MEMORY.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoMemory.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoMemory);
        //磁盘top
        MwLayoutDetailInfo layoutDetailInfoDiskTop = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(6);
        layoutGrid.setY(0);
        layoutGrid.setW(6);
        layoutGrid.setH(2);
        layoutDetailInfoDiskTop.setLayoutGrid(layoutGrid);
        layoutDetailInfoDiskTop.setComponentName("磁盘(对应磁盘使用率)");
        layoutDetailInfoDiskTop.setComponentType(top5.getItemName());
        layoutDetailInfoDiskTop.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        itemDropInfo = new ItemDropInfo();
        itemDropInfo.setChName(DISK.getChineseName());
        itemDropInfo.setUnits("%");
        itemDropInfo.setDelay("600s");
        itemDropInfo.setValue_type(0);

        if(map!=null && map.containsKey(DISK.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(DISK.getEnglishName());
            itemDropInfo.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfo.setUnits(resultParam.getUnits());
            itemDropInfo.setDelay(resultParam.getDelay());
            itemDropInfo.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfo.setName(DISK.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfo));
        layoutDetailInfoDiskTop.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoDiskTop);
        //接口
        MwLayoutDetailInfo layoutDetailInfoInterface = new MwLayoutDetailInfo();
        layoutGrid = new LayoutGrid();
        layoutGrid.setX(0);
        layoutGrid.setY(4);
        layoutGrid.setW(12);
        layoutGrid.setH(2);
        layoutDetailInfoInterface.setLayoutGrid(layoutGrid);
        layoutDetailInfoInterface.setComponentName("接口");
        layoutDetailInfoInterface.setComponentType(line.getItemName());
        layoutDetailInfoInterface.setId(UUID.randomUUID().toString());
        layoutItemDropInfo = new MwLayoutItemDropInfo();
        ItemDropInfo itemDropInfoInterface01 = new ItemDropInfo();
        itemDropInfoInterface01.setChName(INTERFACE_IN.getChineseName());
        itemDropInfoInterface01.setUnits("bps");
        itemDropInfoInterface01.setDelay("120s");
        itemDropInfoInterface01.setValue_type(3);
        itemDropInfoInterface01.setValuemapid("0");
        if(map!=null && map.containsKey(INTERFACE_IN.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(INTERFACE_IN.getEnglishName());
            itemDropInfoInterface01.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfoInterface01.setUnits(resultParam.getUnits());
            itemDropInfoInterface01.setDelay(resultParam.getDelay());
            itemDropInfoInterface01.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfoInterface01.setName(INTERFACE_IN.getEnglishName());

        ItemDropInfo itemDropInfoInterface02 = new ItemDropInfo();
        itemDropInfoInterface02.setChName(INTERFACE_OUT.getChineseName());
        itemDropInfoInterface02.setUnits("bps");
        itemDropInfoInterface02.setDelay("120s");
        itemDropInfoInterface02.setValue_type(3);
        itemDropInfoInterface02.setValuemapid("0");
        if(map!=null && map.containsKey(INTERFACE_OUT.getEnglishName())){
            MwZabbixItemResultParam resultParam = map.get(INTERFACE_OUT.getEnglishName());
            itemDropInfoInterface02.setValue_type(intValueConvert(resultParam.getValue_type()));
            itemDropInfoInterface02.setUnits(resultParam.getUnits());
            itemDropInfoInterface02.setDelay(resultParam.getDelay());
            itemDropInfoInterface02.setValuemapid(resultParam.getValuemapid());
        }
        itemDropInfoInterface02.setName(INTERFACE_OUT.getEnglishName());
        layoutItemDropInfo.setItemInfos(Arrays.asList(itemDropInfoInterface01, itemDropInfoInterface02));
        layoutDetailInfoInterface.setDisplayData(layoutItemDropInfo);
        layout.add(layoutDetailInfoInterface);
        overViewLayout.setLayout(layout);
        componentLayoutList.add(overViewLayout);
        return componentLayoutList;
    }

}
